Quickstart Expo
This guide will help you to implement the Group Link Mobile SDK on your application written in React Native using the Expo framework on the managed workflow.
Step 1 - Installing the Group Link Expo Library
Inside the root of your expo managed project, you need to install some libraries to set up the necessary environment, there are some essential libraries you will need to install as shown below.
- expo-notifications
- expo-constants
- rn-grouplink-sdk
- grouplink-sdk-expo-plugin
npx expo install expo-notifications &&
npx expo install expo-constants &&
npm install @grouplinknetwork/rn-grouplink-sdk &&
npm install @grouplinknetwork/grouplink-sdk-expo-plugin
Step 2 - Plugin Configuration
After you installed all the necessary libraries, you will need to set up the Group Link plugin, to do this you have to insert the rn-grouplinksdk-expo-plugin with the necessary options, like the token to initialize the plugin, you need to insert this inside the plugins array on your app.json, you can find this file at the root folder.
"plugins": [
[
"@grouplinknetwork/grouplink-sdk-expo-plugin",
{
"token": "GROUP_LINK_TOKEN"
}
]
]
After this you'll need to run:
npx expo prebuild
Here are all the params you can call within our plugin:
- token - string - The Group Link Initialization token
iOS Specific Configs - You need to call the bluetooth and location permission
- initBluetoothIOS - boolean - The Group Link iOS bluetooth function (this will ask the user permission to use bluetooth) - default is false
- initLocationIOS - boolean - The Group Link iOS location function (this will ask the user permission to use location) - default is false
- initNotificationIOS - boolean - The Group Link iOS notification function (this will ask the user permission to use notifications) - default is false
Info.plist strings - THESE STRINGS WILL NOT OVERRIDE ALREADY SETTED STRINGS
- NSLocationAlwaysAndWhenInUseUsageDescription - string - The ios Core Location Always usage string inside info.plist - default is "Nós precisamos da permissão de localização para uma melhor experiencia de usuario"
- NSLocationWhenInUseUsageDescription - string - The ios Core Location While in Use string inside info.plist - default is "Nós precisamos da permissão de localização para uma melhor experiencia de usuario"
- NSBluetoothPeripheralUsageDescription - string - The ios Core Bluetooth Peripheral usage string inside info.plist - default is "Nós precisamos da permissão de bluetooth para uma melhor experiencia de usuario"
- NSBluetoothAlwaysUsageDescription - string - The ios Core Bluetooth Usage string inside info.plist - default is "Nós precisamos da permissão de bluetooth para uma melhor experiencia de usuario"
Step 3 - Push Notifications Token Setup
To pass get your notification token, you will need to use the expo-notifications and expo-constants libraries, you can get the token string using the function below and send to our SDK via setDevicePushTokenIOS from our React Native SDK.
First, import the necessary depencencies to your application init file.
import Constants from "expo-constants";
import * as GroupLinkSDK from "@grouplinknetwork/rn-grouplink-sdk";
import * as Notifications from "expo-notifications";
After that, insert the parse notification function below
const getPushToken = () => {
if (!Constants.isDevice) {
return Promise.reject("YOU ARE RUNNING ON SIMULATOR");
}
try {
return Notifications.getPermissionsAsync()
.then((statusResult) => {
return statusResult.status !== "granted"
? Notifications.requestPermissionsAsync()
: statusResult;
})
.then((statusResult) => {
if (statusResult.status !== "granted") {
throw "Failed to get push token for push notification!";
}
return Notifications.getDevicePushTokenAsync();
})
.then((tokenData) => tokenData.data);
} catch (error) {
return Promise.reject("Couldn't check notifications permissions");
}
};
You can get the notification token using this function inside your code, we recommend using a useEffect with the application initialization to set the token inside our SDK, don't forget to import the React.
React.useEffect(() => {
getPushToken().then((token) => {
GroupLinkSDK.setDevicePushTokenIOS(token);
});
}, []);